print('Lua Rocks! Rrrrrrr-ocks!')

numframes = 0
deltatime = 0
time = 0
speed = 0

particles = {}


function setup()
  print('setup')
  math.randomseed( os.time() )
  dofile( "particles.lua" )
end

function draw() 
  time = time + deltatime
  speed = time * 2

    table.insert(particles,
    Particle.new( mousx + math.random(-5,5), mousy+math.random(-5,5) )
    )
    
  DrawParticles()

  setcolor(80,32,80)
  

  scalex = math.cos( 5*time ) * 50
  scaley = math.sin( 5*time ) * 50
  
  r = 50+math.cos( 3*time )*25
  maxsegs = 10
  for i=0, maxsegs do
    ang = i * 2*math.pi / (maxsegs-1) + speed
    px = math.cos(ang)*r
    py = math.sin(ang)*r
    finalx = xres/2+px + scalex
    finaly = yres/2+py + scaley
    drawSparkler(finalx,finaly, 4 )
    
      table.insert(particles,
    Particle.new(finalx,finaly)
    )
    
  end
  
  setcolor(255,255,255)
  bmxprintf(10, 10, "numframes " .. numframes)
  bmxprintf(10, 20, "dt: " .. deltatime)
  bmxprintf(10, 60, "particles: " .. #particles)
  
  numframes = numframes + 1
end
